package com.lefevre.cms.service.statistic.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lefevre.cms.bean.statistic.PV;
import com.lefevre.cms.mapper.PvMapper;
import com.lefevre.cms.service.statistic.PageViewService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 页面访问量
 *
 * @author Lefevre
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PageViewServiceImpl extends ServiceImpl<PvMapper, PV> implements PageViewService {

    /**
     * 保存访问量
     *
     * @param pvList 访问量集合
     */
    public void savePageView(List<PV> pvList) {
        if (pvList != null && pvList.size() > 0) {
            for (PV pv : pvList) {
                baseMapper.insert(pv);
            }
        }
    }

    /**
     * 删除访问量
     *
     * @param endTime 结束时间
     */
    public void deletePageView(Date endTime) {
        baseMapper.delete(new LambdaUpdateWrapper<PV>()
                .lt(PV::getTimes, endTime));
    }

}
